package com.zhong.gang.app.utils;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.ItemFahuochangContentBinding;
import com.zhong.gang.applib.bean.MaterialBean;
import com.zhong.gang.applib.utils.NumberUtils;

import java.util.List;

public class MaterialDetailView extends LinearLayout {
    private String[] strings = new String[]{"一","二","三","四","五","六","七","八","九","十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十"};
    public MaterialDetailView(Context context) {
        super(context);
        setOrientation(VERTICAL);
    }

    public MaterialDetailView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setOrientation(VERTICAL);
    }

    public MaterialDetailView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(VERTICAL);
    }

    public void setData(List<MaterialBean> data,boolean status){
        this.removeAllViews();
        for (int n = 0 ;n < data.size();n++){
            MaterialBean bean = data.get(n);
            View view = LayoutInflater.from(getContext()).inflate(R.layout.item_fahuochang_content,null);
            ItemFahuochangContentBinding binding = DataBindingUtil.bind(view);
            binding.weight.setText(bean.getWeight()+"吨");
            binding.typeNum.setText("料型"+strings[n]+":"+bean.getMaterialTypeName());
            binding.type.setText(NumberUtils.getNumber(bean.getPrice())+"元");
            binding.weight.setVisibility(status?VISIBLE:GONE);
            binding.type.setVisibility(status?VISIBLE:GONE);
            this.addView(view);
        }
    }

    public void setData(List<MaterialBean> data){
        setData(data,true);
    }
}